package ru.spbau.design.snmp.android.viewer.model;

import java.util.ArrayList;
import java.util.List;

import ru.spbau.design.snmp.android.viewer.utils.ReplaceableListItem;


public final class SubNet {
	
	public SubNet(
			String id, 
			IPAddress netMask,
			Network network) {
		this.id = id;
		this.netMask = netMask;
		this.nodes = new ArrayList<NetNode>();
		this.routerInterfaces = new ArrayList<NetInterface>();
		this.network = network;
	}
	
	public String getId() {
		return id;
	}
	
	public IPAddress getNetMask() {
		return netMask;
	}
	
	public List<NetInterface> getRouterInterfaces() {
		return routerInterfaces;
	}
	
	public Network getnetwork() {
		return network;
	}
	
	public List<NetNode> getNodes() {
		return nodes;
	}
	
	public void addNode(NetNode node) {
		nodes.add(node);
	}
	
	public void addRouterInterface(NetInterface netInterface) {
		routerInterfaces.add(netInterface);
	}
	
	public ReplaceableListItem<NetNode> getNetNodeByIP(IPAddress ip) {
		for(int i = 0; i < getNodes().size(); ++i) {
			if (getNodes().get(i).getAddress().equals(ip)) {
				return new ReplaceableListItem<NetNode>(i, getNodes());
			}
		}
		return null;
	}

	private ArrayList<NetNode> nodes;
	private final String id;
	private final IPAddress netMask;
	private final List<NetInterface> routerInterfaces;
	private final Network network;
}